/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import main.CheckSerial;

/**
 *
 * @author phat10130059
 */
public class GetHardDiskSeriNumber {

    public static String seri() {

        List<String> list = new ArrayList<String>();
        String t = "";
        try {

            Process p = Runtime.getRuntime().exec("wmic diskdrive get serialnumber");
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    p.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {

                list.add(line);

            }

        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(new CheckSerial(), ex.getMessage(), "error", JOptionPane.ERROR_MESSAGE);
            t = seriChipRam();
            return t;
        }

        for (String str : list) {
            t = t + str.trim();
        }
        
        
        
        if (t.trim().equals("")) {
            t = seriChipRam();
        }

//        System.out.println(t);

        return t;
    }

    public static String seriChipRam() {

        List<String> list = new ArrayList<String>();
        String t = "";
        try {

            Process p = Runtime.getRuntime().exec("wmic memorychip get serialnumber");
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    p.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {

                list.add(line);

            }

        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(new CheckSerial(), ex.getMessage(), "error", JOptionPane.ERROR_MESSAGE);


        }

        for (String str : list) {
            t = t + str.trim();
        }

//        System.out.println(t);

        return t;
    }
//    public static void main(String[] args) throws Exception {
//        String seri = seri();
//        System.out.println(seri);
//    }
}
